import { defineStore } from 'pinia'

export const useTagsViewStore = defineStore('tags-view', () => {
  const tagsViews = ref<TagView[]>([])
  const cacheViews = ref<string[]>([])

  /**
   *
   * @param view {Tagview}
   * @returns
   */
  function addTagsView(view: TagView) {
    if (tagsViews.value.find((v) => v.fullPath === view.fullPath)) {
      return false
    }
    // 如果是固定的，则添加在列表的前面
    if (view.affix) {
      tagsViews.value.unshift(view)
    } else {
      tagsViews.value.push(view)
    }
  }
  /**
   *
   * @param view
   * @returns
   */
  function addCacheViews(view: TagView) {
    const viewName = view.path
    if (cacheViews.value.includes(viewName)) {
      return
    }
    if (view.keepAlive) {
      cacheViews.value.push(viewName)
    }
    console.log(tagsViews.value.entries())
  }

/*   function delTagsViews(view: TagView) {
    return new Promise((resolve) => {
    
      resolve([...tagsViews.value])
    })
  }
 */
  return {
    tagsViews,
    addTagsView,
    addCacheViews
    
  }
})
